package com.example.myblog.controller;


import com.example.myblog.exception.BaseException;
import com.example.myblog.result.ResponseBean;
import com.example.myblog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 叶兴
 * @since 2022-09-29
 */
@RestController
@RequestMapping("/user")
public class UserController {

    UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    /**
     * 更新用户头像
     * @param avatar
     * @return
     * @throws BaseException
     */
    @PostMapping("/upload/avatar")
    public ResponseBean uploadAvatar(@RequestParam MultipartFile avatar) throws BaseException {
        userService.updateAvatar(avatar);
        return ResponseBean.success();
    }

    /**
     * 获取用户基本信息
     * @param username
     * @return
     * @throws BaseException
     */
    @GetMapping("/{username}")
    public ResponseBean getUserInfo(@PathVariable String username) throws BaseException {
        userService.getUserInfo(username);
        return ResponseBean.success();
    }
}
